<template>
  <div>
    <el-input style="width:200px;" v-model="parmas.name" placeholder="请输入内容"></el-input>
     <el-button type="primary" @click="seek"
            >搜索</el-button
          >
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="日期" width="180">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.createdAt }}</span>
        </template>
      </el-table-column>
      <el-table-column label="姓名" prop="name" width="180"></el-table-column>
      <el-table-column
        label="内容"
        prop="content"
        width="180"
      ></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="parmas.page"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="parmas.rows"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      total: 0,
      parmas: {
        page: 1,
        rows: 10,
        name:''
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    seek(){
      this.parmas.page = 1; //恢复默认值 
      this.getList();
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.parmas.rows = val;
      this.getList()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.parmas.page = val;
      this.getList();
    },
    async getList() {
      let res = await this.$axios.get(
        `/wish?page=${this.parmas.page}&rows=${this.parmas.rows}&name=${this.parmas.name}`
      );
      console.log(res);
      if (res.data.code == 200) {
        this.tableData = res.data.data.list;
        this.total = res.data.data.count;
      }
    },

    handleEdit(index, row) {
      console.log(index, row);
      this.$router.push({
        path:"/home/add",
        query:{
          id:row.id
        }
      })
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
  },
};
</script>